/**
 * 将分转换为元的展示字符串：最多保留两位小数，去掉多余的0
 * 规则示例：
 *  - 0      -> "0"
 *  - 10000  -> "100"
 *  - 10010  -> "100.1"
 *  - 10011  -> "100.11"
 */
export function centsToYuan(cents) {
  if (cents === null || cents === undefined || cents === '') return '0';
  const num = Number(cents);
  if (!Number.isFinite(num)) return '0';
  const fixed = (num / 100).toFixed(2);
  // 去除尾部无意义的0与小数点
  return fixed.replace(/\.00$/, '').replace(/(\.\d)0$/, '$1');
}

export default { centsToYuan };


